//
//  HomeFlowServiceCatCell_style2.m
//  BaseProject
//
//  Created by 王洋 on 2020/11/30.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "HomeFlowServiceCatCell_style2.h"

@implementation HomeFlowServiceCatCell_style2

+ (CGFloat)calculateHeight {
    
    CGFloat collectionHeight =  (TTScreenWidth - 45)*0.4356+40+5+2+5;
    return collectionHeight;
}

- (void)awakeFromNib {
    [super awakeFromNib];

    self.itemControl0.userInteractionEnabled = YES;
    self.itemControl1.userInteractionEnabled = YES;
    self.itemControl2.userInteractionEnabled = YES;
    self.itemControl3.userInteractionEnabled = YES;
    self.itemControl4.userInteractionEnabled = YES;

    [self.itemControl0 addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.HomeFlowServiceCatCell_style2Block) {
            [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithType:@"6"];
            self.HomeFlowServiceCatCell_style2Block(HomeFlowServiceCatCell_style2ActionType_item, 0);
        }
    }];

    [self.itemControl1 addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.HomeFlowServiceCatCell_style2Block) {
            [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithType:@"6"];
            self.HomeFlowServiceCatCell_style2Block(HomeFlowServiceCatCell_style2ActionType_item, 1);
        }
    }];
    
    [self.itemControl2 addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.HomeFlowServiceCatCell_style2Block) {
            [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithType:@"6"];
            self.HomeFlowServiceCatCell_style2Block(HomeFlowServiceCatCell_style2ActionType_item, 2);
        }
    }];
    
    [self.itemControl3 addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.HomeFlowServiceCatCell_style2Block) {
            [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithType:@"6"];
            self.HomeFlowServiceCatCell_style2Block(HomeFlowServiceCatCell_style2ActionType_item, 3);
        }
    }];
    
    [self.itemControl4 addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.HomeFlowServiceCatCell_style2Block) {
            [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithType:@"6"];
            self.HomeFlowServiceCatCell_style2Block(HomeFlowServiceCatCell_style2ActionType_item, 4);
        }
    }];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.bottomBGView pp_clipCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight radius:8];
    });
}

- (void)fillCellWithModel:(HomeADItemModel *)model {
    
    if (model.advBackImg.length > 0) {
        [self.itemBGImageView sd_setImageWithURL:[NSURL URLWithString:model.advBackImg] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    } else {
        [self.itemBGImageView setImage:[UIImage imageNamed:@"BAmarriage3"]];
    }
    
    self.dataArray = @[].mutableCopy;
    self.dataArray = model.sysAdvertisement.sysAdvEventList;
    for (int i = 0; i < self.dataArray.count; i++) {
        switch (i) {
            case 0:{
                [self.itemControl0 sd_setImageWithURL:[NSURL URLWithString:self.dataArray[i].url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
            } break;
            case 1:{
                [self.itemControl1 sd_setImageWithURL:[NSURL URLWithString:self.dataArray[i].url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
            } break;
            case 2:{
                [self.itemControl2 sd_setImageWithURL:[NSURL URLWithString:self.dataArray[i].url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
            } break;
            case 3:{
                [self.itemControl3 sd_setImageWithURL:[NSURL URLWithString:self.dataArray[i].url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
            } break;
            case 4:{
                [self.itemControl4 sd_setImageWithURL:[NSURL URLWithString:self.dataArray[i].url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
            } break;
            default:
                break;
        }
    }
}

- (IBAction)newFreeAction:(id)sender {
    if (self.HomeFlowServiceCatCell_style2Block) {
        [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithType:@"6"];
        self.HomeFlowServiceCatCell_style2Block(HomeFlowServiceCatCell_style2ActionType_recommender, -1);
    }
}

- (IBAction)getCouponAction:(id)sender {
    if (self.HomeFlowServiceCatCell_style2Block) {
        [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithType:@"6"];
        self.HomeFlowServiceCatCell_style2Block(HomeFlowServiceCatCell_style2ActionType_getCoupon, -1);
    }
}

- (IBAction)shareGiftAction:(id)sender {
    if (self.HomeFlowServiceCatCell_style2Block) {
        [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithType:@"6"];
        self.HomeFlowServiceCatCell_style2Block(HomeFlowServiceCatCell_style2ActionType_shareGift, -1);
    }
}

@end
